package com.glsc.ngateway.platform.repo.costallocation;

import com.glsc.ngateway.platform.domain.costallocation.IpDetailInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Repository
public interface IpDetailInfoRepo extends JpaRepository<IpDetailInfo, Long>, JpaSpecificationExecutor<IpDetailInfo> {
    @Transactional
    @Modifying
    @Query(value = "delete from t_ipdetail_info u where u.vc_ipinfo_id = :ipInfoId",nativeQuery = true)
    void deleteAllByipInfoId(@Param("ipInfoId") Long ipInfoId);

    @Query(value = "select u  from IpDetailInfo u where u.ipInfoId in :ipInfoIdSet")
    List<IpDetailInfo> queryByIpInfoId(Set<Long> ipInfoIdSet);

    @Query(value = "select u  from IpDetailInfo u where u.ipInfoId in :ipInfoIdSet and u.systemClassNo != :defaultSystemNo ")
    List<IpDetailInfo> queryByIpInfoIdWithoutDefaultSystem(Set<Long> ipInfoIdSet,String defaultSystemNo);
    @Query(value = "select u  from IpDetailInfo u where u.ipInfoId = :ipInfoId")
    List<IpDetailInfo> queryByIpInfoIdOne(@Param("ipInfoId") Long ipInfoId);

    @Query(value = "select u  from IpDetailInfo u where u.systemClassNo = :systemClassNo")
    List<IpDetailInfo> queryBySystemClassNo(String  systemClassNo);


    @Query(value = "select u  from IpDetailInfo u where u.componentCategoryId in :componentCategoryIdSet")
    List<IpDetailInfo> queryByComponentCategoryId(Set<Long> componentCategoryIdSet);

    @Query(value = "select u  from IpDetailInfo u where u.systemClassNo = :defaultSystemNo")
    List<IpDetailInfo> queryByDefaultSystem(String defaultSystemNo);
}
